package com.koron.bean.system.staff.vo;

import com.koron.bean.app.AppSimpleBean;
import com.koron.bean.system.agent.vo.AgentUserVo;
import com.koron.bean.system.org.OrgVo;
import com.koron.bean.system.role.UserOwnJurisdictionBean;
import com.koron.bean.system.staff.StaffBean;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @ClassName EamUser
 * @description
 * @Author zhouj
 * @Date 2021/7/8 11:12
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class EamUser extends StaffBean {

    @ApiModelProperty(value = "用户拥有权限")
    private UserOwnJurisdictionBean userOwnJurisdictionBean;

    @ApiModelProperty(value = "tokenList(主要为了查看多少客户端登录在线)", hidden = true)
    private List<String> tokenList;

    @ApiModelProperty(value = "组织Vo")
    private List<OrgVo> orgVoList;

    @ApiModelProperty(value = "应用下拉列表")
    List<AppSimpleBean> appSimpleBeanList;

    @ApiModelProperty(value = "身份下拉列表(前端默认添加本人)")
    List<AgentUserVo> leaderUserVos;

    @ApiModelProperty(value = "当前数据源", hidden = true)
    private String currDs;

    @ApiModelProperty(value = "当前语种", hidden = true)
    private String language;

    @ApiModelProperty(value = "当前组织", hidden = true)
    private String currOrg;

    @ApiModelProperty(value = "当前身份", hidden = true)
    private String currLeader;

    @ApiModelProperty(value = "当前身份", hidden = true)
    private String currLeaderOrg;

    @ApiModelProperty(value = "代理该账号人的信息", hidden = true)
    private EamUser agent;

    //获取组织id
    @Override
    public String getOrgId() {
        //做一次区分
        String orgId = super.getOrgId();

        if (StringUtils.isEmpty(this.currOrg)) {
            return orgId;
        }

        return this.currOrg;
    }

    //获取组织名称
    @Override
    public String getOrgName() {
        //做一次区分
        String orgName = super.getOrgName();

        if (StringUtils.isEmpty(this.currOrg)) {
            return orgName;
        }

        if (!CollectionUtils.isEmpty(this.orgVoList)) {
            for (OrgVo orgVo : this.orgVoList) {
                if (this.currOrg.equals(orgVo.getId())) {
                    return orgVo.getName();
                }
            }
        }

        return orgName;
    }

    //获取部门id
    @Override
    public String getDeptId() {
        //做一次区分
        String deptId = super.getDeptId();

        if (StringUtils.isEmpty(this.currOrg)) {
            return deptId;
        }
        if (!CollectionUtils.isEmpty(this.orgVoList)) {
            for (OrgVo orgVo : this.orgVoList) {
                if (this.currOrg.equals(orgVo.getId())) {
                    return orgVo.getDeptId();
                }
            }
        }

        return deptId;
    }

    //获取部门名称
    @Override
    public String getDeptName() {
        //做一次区分
        String deptName = super.getDeptName();

        if (StringUtils.isEmpty(this.currOrg)) {
            return deptName;
        }
        if (!CollectionUtils.isEmpty(this.orgVoList)) {
            for (OrgVo orgVo : this.orgVoList) {
                if (this.currOrg.equals(orgVo.getId())) {
                    return orgVo.getDeptName();
                }
            }
        }

        return deptName;
    }

}
